package com.timeriver.component;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component
public class TaskRunnerQueue {

    private static LinkedBlockingQueue<Integer> taskSets = new LinkedBlockingQueue<>(16);

    public static boolean addTask(Integer task) throws Exception {
        return taskSets.add(task);
    }

    @Bean
    private static void runTask() {
        CompletableFuture.supplyAsync(() -> {
            while (true) {
                Integer poll = taskSets.poll();
                if (null != poll) {
                    System.out.println("任务出队，执行中...");
                }
            }
        });
    }
}
